#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
#~~~ Lancet Health & Climate  ~~~
#~~~ Change Conjoint Analysis ~~~
#~~~ 2022-08-17               ~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#### Citation ####

# Replication materials and data for Niheer Dasandi, Hilary Graham, David Hudson, Slava Jankin, Jennifer vanHeerde-Hudson, and Nick Watts, 'Positive, global, and health or environment framing bolsters public support for climate policies', Communications Earth & Environment


#### Install packages, set working directory, load data ####

library(ggpubr)
library(stargazer)
library(sjPlot)
library(FindIt)
library(srvyr)
library(arsenal) # Hahaha - sorry, Niheer! COYS.
library(extrafont)
library(skimr)
library(broom)
library(cregg)
library(haven)
library(labelled)
library(tidyverse)


# load in data for conjoint analysis
df_cj_profiles <- readRDS("CEE_ClimateFrames_df_cj_profiles.rds")


#### Figure S2: Randomization of attribute levels ####
# shows that different levels of characteristics are also evenly spread and randomised
df_cj_profiles %>%
  dplyr::select(id, Valence:Time, country_fac) %>%
  pivot_longer(-c(id, country_fac)) %>%
  group_by(country_fac, name) %>%
  count(value) %>%
  mutate(percent=n/sum(n)*100) %>%
  ggplot(aes(x=value, y=percent), fill="black") +
  geom_col() +
  geom_text(aes(label = round(percent,1), y=percent/2), colour="white", size=2, position = position_dodge(0.9)) +
  facet_grid(rows=vars(country_fac), cols=vars(name), scales="free") +
  theme_minimal() + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  labs(y="Percentage of time shown", x="Attribute level")
  
ggsave("Supplementary_FigS2_distrib_randomisation_levels.pdf", width=20*1.3, height=12.36068*1.3, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS2_distrib_randomisation_levels.pdf", outfile="Supplementary_FigS2_distrib_randomisation_levels.pdf")

# tests for distribution of attribute levels described in text
# Valence
x <- df_cj_profiles %>%
  ungroup() %>%
  select(Valence) %>%
  mutate(Valence = ifelse(Valence=="Opportunity", 1, 0)) %>%
  pull()

# one sample t-test
t.test(x, mu = 0.5, alternative = "two.sided")

# Time
time <- df_cj_profiles %>%
  ungroup() %>%
  select(Time) %>%
  count(Time) %>%
  pull()

# Chi-square Goodness of Fit Test
res <- chisq.test(time, p = c(1/3, 1/3, 1/3))
res
# The p-value of the test is 0.6967, which is greater than the significance level alpha = 0.05. We can conclude that the observed proportions are not significantly different from the expected proportions.
res$expected

# Theme
theme <- df_cj_profiles %>%
  ungroup() %>%
  select(Theme) %>%
  count(Theme) %>%
  pull()

# Chi-square Goodness of Fit Test
res <- chisq.test(theme, p = c(1/4, 1/4, 1/4, 1/4))
res
# The p-value of the test is 0.38, which is greater than the significance level alpha = 0.05. We can conclude that the observed proportions are not significantly different from the expected proportions.

# Scale
scale <- df_cj_profiles %>%
  ungroup() %>%
  select(Scale) %>%
  count(Scale) %>%
  pull()

# Chi-square Goodness of Fit Test
res <- chisq.test(scale, p = c(1/4, 1/4, 1/4, 1/4))
res
# The p-value of the test is 0.3288, which is greater than the significance level alpha = 0.05. We can conclude that the observed proportions are not significantly different from the expected proportions.


#### Figure S3: Three top and three bottom profiles by country ####
# Plot of 96 combinations and how many times chosen
# Top and bottom profiles in each country

top <- df_cj_profiles %>%
  select(w8, country_fac, Chosen, Valence:Time) %>%
  unite(profile, Valence:Time, sep=" | ") %>%
  as_survey_design(id = 1, weight = w8) %>%
  group_by(country_fac, profile) %>%
  #filter(!is.na(country_fac)) %>%
  summarize(percent = survey_mean(Chosen, vartype = "ci", na.rm=TRUE)) %>%
  mutate(percent = percent*100, percent_low = percent_low*100, percent_upp = percent_upp*100) %>%
  group_by(country_fac) %>%
  slice_max(percent, n = 3) %>%
  mutate(scored = "top")

btm <- df_cj_profiles %>%
  select(w8, country_fac, Chosen, Valence:Time) %>%
  unite(profile, Valence:Time, sep=" | ") %>%
  as_survey_design(id = 1, weight = w8) %>%
  group_by(country_fac, profile) %>%
  #filter(!is.na(country_fac)) %>%
  summarize(percent = survey_mean(Chosen, vartype = "ci", na.rm=TRUE)) %>%
  mutate(percent = percent*100, percent_low = percent_low*100, percent_upp = percent_upp*100) %>%
  group_by(country_fac) %>%
  slice_min(percent, n = 3) %>%
  mutate(scored = "bottom")

topbtm <- top %>%
  bind_rows(btm)

topbtm %>%
  mutate(profile = tidytext::reorder_within(profile, percent, country_fac)) %>%
  #mutate(profile = str_replace(profile, '\\___.*', '')) %>%
  ggplot(aes(x = profile, y=percent, fill=scored)) +
  geom_col() +
  tidytext::scale_x_reordered() +
  coord_flip() +
  geom_text(aes(label = round(percent,1), y=percent/2), colour="white", size=2, position = position_dodge(0.9)) +
  facet_wrap(vars(country_fac), nrow=5, scales="free_y") +
  theme_minimal() + 
  #theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
  labs(y="Percentage of occasions selected", x=NULL) +
  theme(legend.position="none") +
  scale_fill_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)")

ggsave("Supplementary_FigS3_topbtm3.pdf", width=20*1.3, height=12.36068*1.3, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS3_topbtm3.pdf", outfile="Supplementary_FigS3_topbtm3.pdf")


#### Figure S4. Conjoint marginal means pooled sample ####
# Plot MMs Overall

# formula for all conjoint plots
f1 <- Chosen ~ Valence + Theme + Scale + Time

# plot ALL
mm_all <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5)

mm_all <- mm_all %>%
  mutate(sig_col = case_when(p <= 0.05 ~ "Significant",
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Significant", "Not significant")))

mm_all %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=2) +
  geom_hline(yintercept=0.5, colour="grey") +
  coord_flip() +
  ylim(0.4,0.6) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") + 
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_wrap(vars(feature), ncol=1, scales ="free_y", strip.position ="right") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#343a79", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS4_conjoint_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS4_conjoint_ALL_mm.pdf", outfile="Supplementary_FigS4_conjoint_ALL_mm.pdf")


#### Figure S5. Conjoint marginal means country samples ####
# plot COUNTRIES individually (without pooled)

mm_country <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~as.character(country_fac))

mm_country <- mm_country %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(country_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("China", "Germany", "United Kingdom", "India", "United States", "Not significant")))  %>%
  mutate(country_fac = factor(country_fac, levels=c("China", "Germany", "United Kingdom", "India", "United States")))  %>%
  mutate(sig_col_bin = case_when(p <= 0.05 ~ "Significant",
                                 p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col_bin = factor(sig_col_bin, levels=c("Significant", "Not significant")))

mm_country %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col_bin)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") + #,
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(country_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#343a79", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS5_conjoint_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS5_conjoint_COUNTRY_mm.pdf", outfile="Supplementary_FigS5_conjoint_COUNTRY_mm.pdf")


#### Figure S6. Conjoint marginal means pooled sample conditioned on concern ####
# Plot MMs concern binary 
# concerned and not concerned

mm_concern <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~concern_fac_r_bin)

mm_concern <- mm_concern %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(concern_fac_r_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Not concerned", "Concerned", "Not significant")))

mm_concern %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(concern_fac_r_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS6_conjoint_CONCERN_ALL_mm_2.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS6_conjoint_CONCERN_ALL_mm_2.pdf", outfile="Supplementary_FigS6_conjoint_CONCERN_ALL_mm_2.pdf")


#### Figure S7. Conjoint marginal means country samples conditioned on concern ####
# plot concern binary BY country
# concerned and not concerned
mm_concern_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~concern_fac_r_bin) %>%
  mutate(country="China")
mm_concern_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~concern_fac_r_bin) %>%
  mutate(country="Germany")
mm_concern_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~concern_fac_r_bin) %>%
  mutate(country="United Kingdom")
mm_concern_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~concern_fac_r_bin) %>%
  mutate(country="India")
mm_concern_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~concern_fac_r_bin) %>%
  mutate(country="United States")

mm_concern_countries <- mm_concern_cn %>%
  bind_rows(mm_concern_de, mm_concern_uk, mm_concern_in, mm_concern_us)

mm_concern_countries <- mm_concern_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(concern_fac_r_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Not concerned", "Concerned", "Not significant")))


plot(vline=0.5, mm_concern_countries, size=1, by= ~as.character(concern_fac_r_bin), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  #labs(#title="Not concerned versus concerned. All 5 countries individually",
  #caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=200))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS7_conjoint_CONCERN_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS7_conjoint_CONCERN_COUNTRY_mm.pdf", outfile="Supplementary_FigS7_conjoint_CONCERN_COUNTRY_mm.pdf")


#### Figure S8. Conjoint marginal means pooled sample conditioned on care about the environment ####
#Plot MMs care_climate
mm_care <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~care_climate_fac)

mm_care <- mm_care %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(care_climate_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Not selected", "Selected", "Not significant")))

mm_care %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(care_climate_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS8_conjoint_care_climate_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS8_conjoint_care_climate_ALL_mm.pdf", outfile="Supplementary_FigS8_conjoint_care_climate_ALL_mm.pdf")


#### Figure S9. Conjoint marginal means country samples conditioned on care about the environment ####
# plot care_climate BY country
mm_care_climate_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~care_climate_fac) %>%
  mutate(country="China")
mm_care_climate_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~care_climate_fac) %>%
  mutate(country="Germany")
mm_care_climate_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~care_climate_fac) %>%
  mutate(country="United Kingdom")
mm_care_climate_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~care_climate_fac) %>%
  mutate(country="India")
mm_care_climate_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~care_climate_fac) %>%
  mutate(country="United States")

mm_care_climate_countries <- mm_care_climate_cn %>%
  bind_rows(mm_care_climate_de, mm_care_climate_uk, mm_care_climate_in, mm_care_climate_us)

mm_care_climate_countries <- mm_care_climate_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(care_climate_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Not selected", "Selected", "Not significant")))


plot(vline=0.5, mm_care_climate_countries, size=1, by= ~as.character(care_climate_fac), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="Not concerned versus concerned. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=200))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS9_conjoint_CARE_CLIMATE_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS9_conjoint_CARE_CLIMATE_COUNTRY_mm.pdf", outfile="Supplementary_FigS9_conjoint_CARE_CLIMATE_COUNTRY_mm.pdf")


#### Figure S10. Conjoint marginal means pooled sample conditioned on gender ####
# Plot MMs Gender

mm_gender_bin <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~gender_fac_bin)

mm_gender_bin <- mm_gender_bin %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(gender_fac_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Male", "Female", "Not significant")))

mm_gender_bin %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(gender_fac_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS10_conjoint_GENDER_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS10_conjoint_GENDER_ALL_mm.pdf", outfile="Supplementary_FigS10_conjoint_GENDER_ALL_mm.pdf")

#### Figure S11. Conjoint marginal means country samples conditioned on gender ####
# gender by all 5 countries individually
mm_gender_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~gender_fac_bin) %>%
  mutate(country="China")
mm_gender_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~gender_fac_bin) %>%
  mutate(country="Germany")
mm_gender_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~gender_fac_bin) %>%
  mutate(country="United Kingdom")
mm_gender_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~gender_fac_bin) %>%
  mutate(country="India")
mm_gender_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~gender_fac_bin) %>%
  mutate(country="United States")

mm_gender_countries <- mm_gender_cn %>%
  bind_rows(mm_gender_de, mm_gender_uk, mm_gender_in, mm_gender_us)

mm_gender_countries <- mm_gender_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(gender_fac_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Male", "Female", "Not significant")))

plot(vline=0.5, mm_gender_countries, size=1, by= ~as.character(gender_fac_bin), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="Gender. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS11_conjoint_GENDER_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS11_conjoint_GENDER_COUNTRY_mm.pdf", outfile="Supplementary_FigS11_conjoint_GENDER_COUNTRY_mm.pdf")


#### Figure S11. Conjoint marginal means pooled sample conditioned on age ####
# Plot MMs Age
mm_age <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~agecat_bin)

mm_age <- mm_age %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(agecat_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("18-29", "30+", "Not significant")))

mm_age %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(agecat_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS11_conjoint_AGE_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS11_conjoint_AGE_ALL_mm.pdf", outfile="Supplementary_FigS11_conjoint_AGE_ALL_mm.pdf")


#### Figure S12. Conjoint marginal means country samples conditioned on age ####
# plot age binary BY country
# agecat_bin 18-29
mm_agecat_bin_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~agecat_bin) %>%
  mutate(country="China")
mm_agecat_bin_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~agecat_bin) %>%
  mutate(country="Germany")
mm_agecat_bin_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~agecat_bin) %>%
  mutate(country="United Kingdom")
mm_agecat_bin_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~agecat_bin) %>%
  mutate(country="India")
mm_agecat_bin_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~agecat_bin) %>%
  mutate(country="United States")

mm_agecat_bin_countries <- mm_agecat_bin_cn %>%
  bind_rows(mm_agecat_bin_de, mm_agecat_bin_uk, mm_agecat_bin_in, mm_agecat_bin_us)

mm_agecat_bin_countries <- mm_agecat_bin_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(agecat_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("18-29", "30+", "Not significant")))


plot(vline=0.5, mm_agecat_bin_countries, size=1, by= ~as.character(agecat_bin), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="Not concerned versus concerned. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS12_conjoint_AGE_BIN_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS12_conjoint_AGE_BIN_COUNTRY_mm.pdf", outfile="Supplementary_FigS12_conjoint_AGE_BIN_COUNTRY_mm.pdf")



#### Figure S13. Conjoint marginal means pooled sample conditioned on generation ####
# Plots MMs GENERATION
mm_generation <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~generation)

mm_generation <- mm_generation %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(generation),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Generation Z", "Millennial", "Generation X", "Baby Boomer", "Silent Generation", "Not significant")))

levels(mm_generation$sig_col)

mm_generation %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") +#,
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(generation), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#2E3B68", "#E88B3A", "#009972", "#0076A7", "#d94e28", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right", nrow=2, byrow=TRUE))

ggsave("Supplementary_FigS13_conjoint_GENERATION_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS13_conjoint_GENERATION_ALL_mm.pdf", outfile="Supplementary_FigS13_conjoint_GENERATION_ALL_mm.pdf")

#### Figure S14. Conjoint marginal means country samples conditioned on generation ####
# plot generation BY country
# generation
mm_generation_cn <- subset(df_cj_profiles, country_fac=="China") # hsve to remove empty levels in China and India
mm_generation_cn$generation <- droplevels(mm_generation_cn$generation)

mm_generation_cn <- cj(mm_generation_cn, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~generation) %>%
  mutate(country="China")
mm_generation_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~generation) %>%
  mutate(country="Germany")
mm_generation_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~generation) %>%
  mutate(country="United Kingdom")

mm_generation_in <- subset(df_cj_profiles, country_fac=="India") # hsve to remove empty levels in China and India
mm_generation_in$generation <- droplevels(mm_generation_in$generation)
mm_generation_in %>%
  count(generation, Valence)

mm_generation_in <- cj(mm_generation_in, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~generation) %>%
  mutate(country="India")
mm_generation_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~generation) %>%
  mutate(country="United States")

mm_generation_countries <- mm_generation_cn %>%
  bind_rows(mm_generation_de, mm_generation_uk, mm_generation_in, mm_generation_us)

mm_generation_countries <- mm_generation_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(generation),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Generation Z", "Millennial", "Generation X", "Baby Boomer", "Silent Generation", "Not significant")))

plot(vline=0.5, mm_generation_countries, size=1, by= ~as.character(generation), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  #labs(#title="Not concerned versus concerned. All 5 countries individually",
  #caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#2E3B68", "#E88B3A", "#009972", "#0076A7", "#d94e28", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right", nrow=2, byrow=TRUE))

ggsave("Supplementary_FigS14_conjoint_GENERATION_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS14_conjoint_GENERATION_COUNTRY_mm.pdf", outfile="Supplementary_FigS14_conjoint_GENERATION_COUNTRY_mm.pdf")


#### Figure S15. Conjoint marginal means pooled sample conditioned on university education ####
# Plot MMs EDUCATION
mm_educ <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~educ_uni_fac)

mm_educ <- mm_educ %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(educ_uni_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("No University Degree", "University Degree", "Not significant")))

mm_educ %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(educ_uni_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS15_conjoint_EDUCATION_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS15_conjoint_EDUCATION_ALL_mm.pdf", outfile="Supplementary_FigS15_conjoint_EDUCATION_ALL_mm.pdf")

#### Figure S16. Conjoint marginal means country samples conditioned on university education ####
# education by all 5 countries individually
# educ_uni_fac
mm_educ_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~educ_uni_fac) %>%
  mutate(country="China")
mm_educ_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~educ_uni_fac) %>%
  mutate(country="Germany")
mm_educ_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~educ_uni_fac) %>%
  mutate(country="United Kingdom")
mm_educ_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~educ_uni_fac) %>%
  mutate(country="India")
mm_educ_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~educ_uni_fac) %>%
  mutate(country="United States")

mm_educ_countries <- mm_educ_cn %>%
  bind_rows(mm_educ_de, mm_educ_uk, mm_educ_in, mm_educ_us)

mm_educ_countries <- mm_educ_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(educ_uni_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("No University Degree", "University Degree", "Not significant")))

plot(vline=0.5, mm_educ_countries, size=1, by= ~as.character(educ_uni_fac), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="University education. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS16_conjoint_EDUC_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS16_conjoint_EDUC_COUNTRY_mm.pdf", outfile="Supplementary_FigS16_conjoint_EDUC_COUNTRY_mm.pdf")




#### Figure S17. Conjoint marginal means pooled sample conditioned on children ####
# Plot MMs CHILDREN
mm_children_bin <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~children_bin)

mm_children_bin <- mm_children_bin %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(children_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Yes", "No", "Not significant")))

mm_children_bin %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(children_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS17_conjoint_CHILDREN_ALL_mm_2.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS17_conjoint_CHILDREN_ALL_mm_2.pdf", outfile="Supplementary_FigS17_conjoint_CHILDREN_ALL_mm_2.pdf")


#### Figure S18. Conjoint marginal means country samples conditioned on children ####
# plot have children BY country
# children_bin
mm_children_bin_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~children_bin) %>%
  mutate(country="China")
mm_children_bin_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~children_bin) %>%
  mutate(country="Germany")
mm_children_bin_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~children_bin) %>%
  mutate(country="United Kingdom")
mm_children_bin_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~children_bin) %>%
  mutate(country="India")
mm_children_bin_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~children_bin) %>%
  mutate(country="United States")

mm_children_bin_countries <- mm_children_bin_cn %>%
  bind_rows(mm_children_bin_de, mm_children_bin_uk, mm_children_bin_in, mm_children_bin_us)

mm_children_bin_countries <- mm_children_bin_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(children_bin),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("No", "Yes", "Not significant")))


plot(vline=0.5, mm_children_bin_countries, size=1, by= ~as.character(children_bin), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="Not concerned versus concerned. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS18_conjoint_CHILDREN_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS18_conjoint_CHILDREN_COUNTRY_mm.pdf", outfile="Supplementary_FigS18_conjoint_CHILDREN_COUNTRY_mm.pdf")


#### Figure S19. Conjoint marginal means pooled sample conditioned on employment status ####
 #Plot MMs EMPLOYMENT
mm_employ <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~work_status_fac3)

mm_employ <- mm_employ %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(work_status_fac3),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Employed", "Unemployed", "Retired", "Student", "Not significant")))

mm_employ %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(work_status_fac3), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#2E3B68", "#E88B3A", "#009972", "#0076A7", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS19_conjoint_EMPLOYMENT_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS19_conjoint_EMPLOYMENT_ALL_mm.pdf", outfile="Supplementary_FigS19_conjoint_EMPLOYMENT_ALL_mm.pdf")


#### Figure S20. Conjoint marginal means country samples conditioned on employment status ####
# employment by all 5 countries individually
# work_status_fac3
mm_employ_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~work_status_fac3) %>%
  mutate(country="China")
mm_employ_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~work_status_fac3) %>%
  mutate(country="Germany")
mm_employ_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~work_status_fac3) %>%
  mutate(country="United Kingdom")
mm_employ_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~work_status_fac3) %>%
  mutate(country="India")
mm_employ_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~work_status_fac3) %>%
  mutate(country="United States")

mm_employ_countries <- mm_employ_cn %>%
  bind_rows(mm_employ_de, mm_employ_uk, mm_employ_in, mm_employ_us)

mm_employ_countries <- mm_employ_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(work_status_fac3),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Employed", "Unemployed", "Retired", "Student", "Not significant")))

plot(vline=0.5, mm_employ_countries, size=1, by= ~as.character(work_status_fac3), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="University education. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#2E3B68", "#E88B3A", "#009972", "#0076A7", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS20_conjoint_EMPLOYMENT_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS20_conjoint_EMPLOYMENT_COUNTRY_mm.pdf", outfile="Supplementary_FigS20_conjoint_EMPLOYMENT_COUNTRY_mm.pdf")





#### Figure S21. Conjoint marginal means pooled sample conditioned on income ####
# Plot MMs by income
mm_income_mean <- cj(df_cj_profiles, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~income_mean)

mm_income_mean <- mm_income_mean %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(income_mean),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Below average", "Above average", "Not significant")))

mm_income_mean %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means",
    caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(income_mean), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS21_conjoint_INCOME_ALL_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS21_conjoint_INCOME_ALL_mm.pdf", outfile="Supplementary_FigS21_conjoint_INCOME_ALL_mm.pdf")


####Figure S22. Conjoint marginal means country samples conditioned on income ####
# income by all 5 countries individually
mm_income_cn <- cj(subset(df_cj_profiles, country_fac=="China"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~income_mean) %>%
  mutate(country="China")
mm_income_de <- cj(subset(df_cj_profiles, country_fac=="Germany"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~income_mean) %>%
  mutate(country="Germany")
mm_income_uk <- cj(subset(df_cj_profiles, country_fac=="United Kingdom"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~income_mean) %>%
  mutate(country="United Kingdom")
mm_income_in <- cj(subset(df_cj_profiles, country_fac=="India"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~income_mean) %>%
  mutate(country="India")
mm_income_us <- cj(subset(df_cj_profiles, country_fac=="United States"), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~income_mean) %>%
  mutate(country="United States")

mm_income_countries <- mm_income_cn %>%
  bind_rows(mm_income_de, mm_income_uk, mm_income_in, mm_income_us)

mm_income_countries <- mm_income_countries %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(income_mean),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Below average", "Above average", "Not significant")))

plot(vline=0.5, mm_income_countries, size=1, by= ~as.character(income_mean), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  labs(#title="income. All 5 countries individually",
    caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS22_conjoint_INCOME_COUNTRY_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS22_conjoint_INCOME_COUNTRY_mm.pdf", outfile="Supplementary_FigS22_conjoint_INCOME_COUNTRY_mm.pdf")


#### Figure S23. Conjoint marginal means for full sample and reduced WTP=0 sample. ####
# Run conjoint mms with WTP=0 respondents removed
# plot COUNTRIES individually (without pooled)
names(df_cj_profiles)

mm_country_wtp <- cj(subset(df_cj_profiles, rating_norm>0), f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~as.character(country_fac))


mm_country_wtp <- mm_country_wtp %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(country_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("China", "Germany", "United Kingdom", "India", "United States", "Not significant")))  %>%
  mutate(country_fac = factor(country_fac, levels=c("China", "Germany", "United Kingdom", "India", "United States")))  %>%
  mutate(sig_col_bin = case_when(p <= 0.05 ~ "Significant",
                                 p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col_bin = factor(sig_col_bin, levels=c("Significant", "Not significant")))

mm_country$sample <- "Full sample"
mm_country_wtp$sample <- "WTP=0 removed"

mm_country_wtp2 <- mm_country %>%
  bind_rows(mm_country_wtp)

head(mm_country_wtp2)

mm_country_wtp2 %>%
  ggplot(aes(x=level, y=estimate, colour=sample, alpha=sig_col_bin)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") + #,
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(country_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#343a79","#d94e28", "#d9e4eb"), name="(<0.05)") +
  scale_alpha_manual(values = c(1, 0.3)) +
  guides(colour = guide_legend(title.position = "right")) +
  guides(alpha="none")

ggsave("Supplementary_FigS23_conjoint_COUNTRY_mm_WTP.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS23_conjoint_COUNTRY_mm_WTP.pdf", outfile="Supplementary_FigS23_conjoint_COUNTRY_mm_WTP.pdf")



#### Figure S24. Conjoint marginal means pooled sample for August 2020 pilot.####
# Load the data from the August 2020 pilot. Used to test questions and power.
# Lancet_df_cj_profiles_pilot.rds

df_cj_profiles_pilot <- readRDS("CEE_ClimateFrames_August_pilot.rds")

# plot ALL
mm_all <- cj(df_cj_profiles_pilot, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5)

mm_all <- mm_all %>%
  mutate(sig_col = case_when(p <= 0.05 ~ "Significant",
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("Significant", "Not significant")))

mm_all %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=2) +
  geom_hline(yintercept=0.5, colour="grey") +
  coord_flip() +
  ylim(0.4,0.6) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") + 
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=210))  + 
  facet_wrap(vars(feature), ncol=1, scales ="free_y", strip.position ="right") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#343a79", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS24_conjoint_ALL_pilot_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS24_conjoint_ALL_pilot_mm.pdf", outfile="Supplementary_FigS24_conjoint_ALL_pilot_mm.pdf")


#### Figure S25. Conjoint marginal means country samples for August 2020 pilot. ####
# plot COUNTRIES individually (without pooled)

mm_country <- cj(df_cj_profiles_pilot, f1, id = ~ id, weights = ~ w8, estimate = "mm", h0 = 0.5, by= ~as.character(country_fac))

mm_country <- mm_country %>%
  mutate(sig_col = case_when(p <= 0.05 ~ as.character(country_fac),
                             p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col = factor(sig_col, levels=c("China", "Germany", "United Kingdom", "India", "United States", "Not significant")))  %>%
  mutate(country_fac = factor(country_fac, levels=c("China", "Germany", "United Kingdom", "India", "United States")))  %>%
  mutate(sig_col_bin = case_when(p <= 0.05 ~ "Significant",
                                 p > 0.05 ~ "Not significant")) %>%
  mutate(sig_col_bin = factor(sig_col_bin, levels=c("Significant", "Not significant")))

mm_country %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col_bin)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") + #,
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(country_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#343a79", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Supplementary_FigS25_conjoint_COUNTRY_pilot_mm.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Supplementary_FigS25_conjoint_COUNTRY_pilot_mm.pdf", outfile="Supplementary_FigS25_conjoint_COUNTRY_pilot_mm.pdf")






#### Table S1. Descriptive statistics of the sample across the five countries. ####
# load in wide data for summary stats 
df <- readRDS("CEE_ClimateFrames_df.rds")

mylabels_1 <- list(country_fac = "Country",
                   gender_fac = "Gender", 
                   agecat4_fac = "Age categories",
                   income_quintile_fac = "Income quintile", 
                   educ_uni_fac = "University education",
                   children_bin = "Children",
                   work_status_fac2 = "Employment status",
                   concern_fac = "Concern",
                   care_climate_fac = "Care about the climate",
                   income_mean = "Income")

tab1 <- tableby(country_fac ~ gender_fac + agecat4_fac + educ_uni_fac + children_bin + work_status_fac2 + concern_fac + care_climate_fac + income_mean, data=df, weights=w8)

summary(tab1, labelTranslations = mylabels_1, title='Descriptive Statistics')
write2word(tab1, labelTranslations = mylabels_1,
           "Supplementary_TableS1_descrip_stats_tables.doc", title="Descriptive Statistics")



#### Table S3. Randomisation distributions ####
# Descriptives on the randomisation
df_cj_profiles <- df_cj_profiles %>%
  mutate(shown_fac = factor(shown))
tab2 <- tableby(country_fac ~ shown_fac, data=df_cj_profiles, weights=w8)

mylabels_2 <- list(country_fac = "Country",
                   shown_fac = "Profile Shown")

summary(tab2, labelTranslations = mylabels_2, title='Randomisation Statistics')
write2word(tab2, labelTranslations = mylabels_2,
           "Supplementary_TableS3_randomisation_stats_tables.doc", title="Randomisation Statistics")


####  Table S4: Robustness test of choice consistency regression results. ####
# create separate datasets for regressions
df_cj_profiles_UK <- subset(df_cj_profiles, country_fac=="United Kingdom")
df_cj_profiles_US <- subset(df_cj_profiles, country_fac=="United States")
df_cj_profiles_DE <- subset(df_cj_profiles, country_fac=="Germany")
df_cj_profiles_IN <- subset(df_cj_profiles, country_fac=="India")
df_cj_profiles_CH <- subset(df_cj_profiles, country_fac=="China")

#library(lmerTest)
names(df_cj_profiles_UK)
m_UK <- lmer(rating_norm ~ Chosen + (1 | id), data = df_cj_profiles_UK, weights = w8)
tab_model(m_UK)

m_US <- lmer(rating_norm ~ Chosen + (1 | id), data = df_cj_profiles_US, weights = w8)
tab_model(m_US)

m_CH <- lmer(rating_norm ~ Chosen + (1 | id), data = df_cj_profiles_CH, weights = w8)
tab_model(m_CH)

m_DE <- lmer(rating_norm ~ Chosen + (1 | id), data = df_cj_profiles_DE, weights = w8)
tab_model(m_DE)

m_IN <- lmer(rating_norm ~ Chosen + (1 | id), data = df_cj_profiles_IN, weights = w8)
tab_model(m_IN)

stargazer(m_CH,
          m_DE,
          m_IN,
          m_UK,
          m_US,
          dep.var.labels=c("Rating (z)"),
          column.labels=c("China","Germany", "India", "UK", "US"),
          type="html", out="Supplementary_TableS4.htm")



#### Main Paper: Figure 1. Effects of different climate frames on respondents’ support for climate policies ####

mm_country %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col_bin)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(#title="All 5 countries pooled",
    x=NULL, y="Marginal means") + #,
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(country_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_text(size=9),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=9),
        axis.text.x=element_text(size=7),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#343a79", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Figure1.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Figure1.pdf", outfile="Figure1.pdf")



#### Main Paper: Figure 2. Pooled results of the effects of different climate frames on support for climate policies across subgroups of respondents ####
# Grouped plots of all variables

plot_concern <- mm_concern %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Concern",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(concern_fac_r_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
        legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

plot_care <- mm_care %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Care about climate",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(care_climate_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
                legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
    guides(colour = guide_legend(title.position = "right"))

plot_gender <- mm_gender_bin %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Gender",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(gender_fac_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
                legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
    guides(colour = guide_legend(title.position = "right"))

plot_age <- 
  mm_age %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Age",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(agecat_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
                legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
    guides(colour = guide_legend(title.position = "right"))
  
plot_educ <- mm_educ %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Education",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(educ_uni_fac), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
                legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
    guides(colour = guide_legend(title.position = "right"))

plot_employ <- mm_employ %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  labs(title="Employment status",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(work_status_fac3), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
                legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_y_continuous(limits=c(0.3, 0.7), breaks=c(0.3, 0.5, 0.7)) +
  scale_colour_manual(values=c("#2E3B68", "#E88B3A", "#009972", "#0076A7", "#d9e4eb"), name="(<0.05)") +
    guides(colour = guide_legend(title.position = "right"))
  
plot_income <-mm_income_mean %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Income",
    x=NULL, y="Marginal means") +
    #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(income_mean), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
        legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb", title=NULL)) +
  guides(colour = guide_legend(title.position = "right"))
  
plot_children <- mm_children_bin %>%
  ggplot(aes(x=level, y=estimate, colour=sig_col)) +
  geom_hline(yintercept=0.5, colour="grey") +
  geom_errorbar(aes(ymin=lower, ymax=upper), width=0) +
  geom_point(size=1) +
  coord_flip() +
  ylim(0.3,0.7) +
  labs(title="Children",
    x=NULL, y="Marginal means") +
  #caption=str_wrap("\nSample size n=7,512 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=206))  +
  facet_grid(rows=vars(feature), 
             cols=vars(children_bin), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.text=element_text(size=5),
        plot.title = element_text(size=10, hjust = 0.5), 
        strip.text = element_text(size=6),
        legend.title=element_blank(),
        legend.position="bottom", 
        plot.caption.position = "plot",
        axis.title.x=element_text(size=6),
        axis.text.x=element_text(size=6),
        axis.title.y=element_text(size=6),
        axis.text.y=element_text(size=6),
        plot.caption = element_text(size=3, colour="dark grey", hjust=0)) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
    guides(colour = guide_legend(title.position = "right"))

ggarrange(plot_gender, plot_age, plot_educ, plot_income, plot_employ, plot_concern, ncol=2, nrow=3)
  
ggsave("Figure2.pdf", width=21*.8, height=29.7*.8, unit="cm", dpi=300)
embed_fonts("Figure2.pdf", outfile="Figure2.pdf")



#### Main Paper: Figure 3. Effects of different climate frames on support for climate policies for respondents concerned about climate change and respondents not concerned about climate change for individual countries ####


plot(vline=0.5, mm_concern_countries, size=1, by= ~as.character(concern_fac_r_bin), feature_headers = FALSE) + #, xlim = c(0.4,0.6)) +
  #labs(#title="Not concerned versus concerned. All 5 countries individually",
  #caption=str_wrap("\nSample size: China n=1,502, Germany n=1,501, United Kingdom n=1,500, India=1,506, United States n=1,503 | Data are weighted to be nationally representative | Fieldwork by Deltapoll, October 2020 | Question: Respondents were shown two statements in which the valence, theme, scale, and time frame were varied at random, providing 96 possible permutations.\nRespondents were asked: Indicate which of the two statements would make you more likely to support policies to tackle climate change.", width=200))  + 
  facet_grid(rows=vars(feature), 
             cols=vars(country), 
             scales = "free_y") +
  theme_minimal() +
  theme(legend.title=element_blank(), 
        legend.position="bottom", 
        plot.caption.position =  "plot",
        axis.title.x=element_text(size=9),
        plot.caption = element_text(size=6, colour="dark grey", hjust=0)) +
  aes(colour=sig_col) +
  scale_colour_manual(values=c("#E88B3A", "#009972", "#d9e4eb"), name="(<0.05)") +
  guides(colour = guide_legend(title.position = "right"))

ggsave("Figure3.pdf", width=20, height=12.36068, unit="cm", dpi=300)
embed_fonts("Figure3.pdf", outfile="Figure3.pdf")



